package com.weizai.carshop.controller;

import cn.hutool.core.bean.BeanUtil;
import com.weizai.carshop.common.enumeration.AppHttpCodeEnum;
import com.weizai.carshop.common.result.ResponseResult;
import com.weizai.carshop.model.dto.ShopListDto;
import com.weizai.carshop.model.entiity.GoodsInfoEntity;
import com.weizai.carshop.model.entiity.ShopInfoList;
import com.weizai.carshop.service.ShopListService;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/admin/shopinfo")
@RequiredArgsConstructor
public class ShopInfoListController {
    @Autowired
    private ShopListService shopListService;

    /**
     * 根据栏目类型获取商品列表
     */
    @GetMapping("/list")
    public ResponseResult list(@RequestParam(defaultValue = "1") Long id) {
        List<ShopInfoList> list = shopListService.lambdaQuery().eq(ShopInfoList::getPidId, id).list();
        return ResponseResult.okResult(list);
    }

    /**
     * 添加修改
     */
    @PostMapping("/set")
    public ResponseResult add(@RequestBody  ShopListDto shopListDto) {
        ShopInfoList info = BeanUtil.copyProperties(shopListDto, ShopInfoList.class);
        shopListService.saveOrUpdate(info);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
    /**
     * 删除商品
     */
    @DeleteMapping("/del/{id}")
    public ResponseResult del(@PathVariable("id") Long id) {
        shopListService.removeById(id);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

}
